﻿/*
   Author: Tomer Paz
   games.com
   2007
*/
// the single field Data model
package monopoly.Field {
	
	import flash.events.Event;
	import flash.events.EventDispatcher;
	import flash.display.Loader;
	import monopoly.Player.*;

	public class Field extends EventDispatcher
		{
		/* Field Types */
		
		public static const TYPE_QUEST		= 0;
		public static const TYPE_PROPERTY	= 1;
		public static const TYPE_OTHER		= 2;
		
		/* Property Field status */
		
		public static const NO_OWNER:uint  = 0;		// equivalent to "Bank"
		public static const HAS_OWNER:uint = 1;
		public static const MORTGAGED:uint = 2;
		
		
		protected var _PropertyID:Number;		// taken from DB
		protected var _Position:int				// position in Array of fields
		protected var _Owner:Player;
		protected var _UpgradeLevel:uint;
		protected var _Group:uint;
		protected var _Cost:Number;
		protected var _MortgageCost:Number;
		protected var _Fee:uint;
		protected var _Status:uint;

		
		/* to be taken from DB */
		
		protected var _PropertyName:String;
		protected var _PropertyType:uint;
		
		protected var _ActivePropertyImage:uint;
		/* view related */
		protected var _X:uint = 0;
		protected var _Y:uint = 0;
		protected var _Size;
		protected var _bitmapL:Loader;	// this shall be a Reference to URLLoaded bitmapData contained in array managed by GameBoard
		
		// init vars during construction - No view update yet!
		
		public function Field(Position:uint, PropertyID:uint, bitmapL:Loader) 
			{
			_Position	= Position;
			_PropertyID	= PropertyID;
			
			_Owner = new BankPlayer( );	// default owner
			_ActivePropertyImage = PropertyID;		// for property Image only
			_bitmapL = bitmapL;
			}
		
		// set new owner
		public function set Owner(Owner:Player):void
			{
			_Owner = Owner;
			
			//whoever listens, please update yourself (probably Field View)
			dispatchEvent(new Event(Event.CHANGE));
			}
		
		public function get Owner():Player
			{
			return (_Owner);
			}
		
		public function get UpgradeLevel():uint
			{
			return _UpgradeLevel;
			}
		public function set UpgradeLevel(NewLevel:uint):void
			{
			_UpgradeLevel = NewLevel;
			//whoever listens, please update yourself (probably Field View)
			dispatchEvent(new Event(Event.CHANGE));
			}
		public function get Group():uint
			{
			return _Group;
			}
		public function set Group(group:uint):void
			{
			_Group = group;
			}
		public function get Cost():Number
			{
			return _Cost;
			}
		public function set Cost(newCost:Number):void
			{
			_Cost = newCost;
			}
		public function get MortgageCost():Number
			{
			return _MortgageCost;
			}
		public function set MortgageCost(newMortgageCost:Number):void
			{
			_MortgageCost = newMortgageCost;
			}
		public function get Fee():uint
			{
			return _Fee;
			}
		public function set Fee(newFee:uint):void
			{
			_Fee = newFee;
			}
		public function get Status():uint
			{
			return _Status;
			}
		public function set Status(newStatus:uint):void
			{
			_Status = newStatus;
			}
		public function get PropertyName():String
			{
			return _PropertyName;
			}
		public function get PropertyType():uint
			{
			return _PropertyType;
			}
		public function set PropertyName(NewName:String):void
			{
			_PropertyName = NewName;
			}
		public function set PropertyType(NewType:uint):void
			{
			_PropertyType = NewType;
			}
			
			
		// set the Active property ID and image for this field.
		public function setActiveProperty(PropertyID:uint, bitmapL:Loader):void
			{
			_ActivePropertyImage = PropertyID;
			_bitmapL = bitmapL;
			
			//whoever listens, please update yourself (probably Field View)
			dispatchEvent(new Event(Event.CHANGE));
			}
		
		public function get ActivePropertyID():uint
			{
			return _ActivePropertyImage;
			}
		public function get ActiveProperty():Loader
			{
			return _bitmapL;
			}
		public function get Position():uint
			{
			return _Position;
			}
		public function get PropertyID():uint
			{
			return _PropertyID;
			}
		
		/* setters and possibly getters to be used by Board Views */
		
		public function set_XY(x_axis:uint, y_axis:uint):void
			{
			_X = x_axis;
			_Y = y_axis;
			//whoever listens, please update yourself (probably Field View)
			dispatchEvent(new Event(Event.CHANGE));
			}
		public function get X():uint
			{
			return _X;
			}
		public function get Y():uint
			{
			return _Y;
			}
		public function get Size():uint
			{
			return _Size;
			}
		public function set Size(size:uint):void
			{
			_Size = size;
			dispatchEvent(new Event(Event.CHANGE));
			}
		}
}